import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;

public class Test2 extends JFrame
{
    JTextField jtf=new JTextField(10);
    JTextArea jta=new JTextArea(6,40);

    public Test2() {
        JPanel p=new JPanel();
        JLabel lb=new JLabel("请输入查询姓名:");
        JButton b1=new JButton("查询");
        b1.addActionListener(new Abc());
        JButton b2=new JButton("关闭");
        b2.addActionListener(e->System.exit(0));

        p.add(lb);
        p.add(jtf);
        p.add(b1);
        p.add(b2);
        p.add(jta);
        getContentPane().add(p);
        setTitle("java程序");
        setSize(800,600);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main (String[] args) {
        new Test2();
    }
    class Abc implements ActionListener{
        public void actionPerformed(ActionEvent e){
            String xh2=jtf.getText();
            boolean find=false;
            try {
                Scanner sc=new Scanner(new File("Data.txt"));
                while(sc.hasNextLine()){
                    String s=sc.nextLine();
                    String[] aa=s.split("\\s+");
                    if(xh2.equals(aa[0])){
                        find=true;
                        //jta.setText(s);
                        jta.append("姓名"+aa[0]+"\r\n");
                        jta.append("性别"+aa[1]+"\r\n");
                        jta.append("语文"+aa[2]+"\r\n");
                        jta.append("数学"+aa[3]+"\r\n");
                        jta.append("英语"+aa[4]+"\r\n");
                        jta.append("自然"+aa[5]+"\r\n");
                        jta.append("社会"+aa[6]+"\r\n");
                        jta.append("总分"+aa[7]+"\r\n");
                        break;
                    }
                }
                if(find==false){
                    JOptionPane.showMessageDialog(null,"查无此人");
                }
            }
            catch (Exception ex) {
            }
            finally {
            }
        }
    }
}